/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package argtrust.argsys;

import java.util.List;
import java.util.ArrayList;

/**
 *
 * @author Yuqing Tang
 */
public class ArguingNode {

    Argument mArgument;
    List<ArguingLink> mArguingLinkList;

    ArguingNode(Argument arg) {
        mArgument = arg;

    }

    void setArgument(Argument arg) {
        mArgument = arg;
    }
    //---------------------------------------
    ///For dynamic programming usage.
    boolean isMark = false;

    public boolean isMark() {
        return isMark;
    }

    public void mark() {
        this.isMark = true;
    }

    public void unmark() {
        this.isMark = false;
    }

    public void unmarkHierarchy() {
        unmark();
        if (mArguingLinkList == null) {
            return;
        }
        for (ArguingLink arg_link : mArguingLinkList) {
            ArguingNode next_node = arg_link.getDefeaterNode();
            if (next_node.isMark()) {
                next_node.unmarkHierarchy();
            }
        }

    }
    //---------------------------------------

    public Argument getArgument() {
        return mArgument;
    }

    public List<ArguingLink> getArguingLinkList() {
        return mArguingLinkList;
    }

    public void addDefeaterNode(ArguingNode defeater_node, Defeat defeat) {
        if (mArguingLinkList == null) {
            mArguingLinkList = new ArrayList<ArguingLink>();
        }
        ArguingLink d = new ArguingLink(defeater_node,
                defeat);
        mArguingLinkList.add(d);
    }

    public void setDefeaterNodeList(List<ArguingLink> defeater_node_list) {
        mArguingLinkList = defeater_node_list;
    }

    protected void debug_print_(java.io.PrintStream out) {
        mArgument.debug_print(out);
        mark();
        if (mArguingLinkList == null) {
            return;
        }
        out.println(" is defeated by ");
        for (ArguingLink arg_link : mArguingLinkList) {
            ArguingNode next_node = arg_link.getDefeaterNode();
            if (!next_node.isMark()) {
                out.print("[" + arg_link.getDefeat().getDefeatType() + "]");
                next_node.debug_print_(out);
            }
        }
    }

    public void debug_print(java.io.PrintStream out) {
        debug_print_(out);
        unmarkHierarchy();

    }

    protected void debug_print_arguing_links(java.io.PrintStream out) {
        out.println("===");
        out.println(mArgument.getEndInferenceNode().toString());
        if (mArguingLinkList != null) {

            for (ArguingLink arg_link : mArguingLinkList) {
                out.println("---");
                ArguingNode next_node = arg_link.getDefeaterNode();
                out.println(" is " + arg_link.getDefeat().getDefeatType() + " by ");

                out.println(next_node.getArgument().getEndInferenceNode().toString());
                out.println("---");
            }
        }
        out.println("===");
    }
}
